package top.fengleifeng.question;

import java.util.LinkedList;
import java.util.List;

/**
 * @author : fengelfeing
 * @Package : top.fengleifeng.question
 * @Description:
 * @Date: 2020年10月27日5:26 下午
 */
public class Num144二叉树的前序遍历 {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
    class Solution {
        public List<Integer> preorderTraversal(TreeNode root) {
            List<Integer> list = new LinkedList<>();
            cc(root,list);
            return list;
        }
        private void cc(TreeNode root,List<Integer> list){
            if(root==null){
                return;
            }
            list.add(root.val);
            cc(root.left,list);
            cc(root.right,list);
        }
    }
}
